package com.ruoyi.system.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Invitation;
import com.ruoyi.system.service.IInvitationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 帖子管理Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/invitation")
public class InvitationController extends BaseController
{
    @Autowired
    private IInvitationService invitationService;

    /**
     * 查询帖子管理列表
     */
    @RequiresPermissions("system:invitation:list")
    @GetMapping("/list")
    public TableDataInfo list(Invitation invitation)
    {
        startPage();
        List<Invitation> list = invitationService.selectInvitationList(invitation);
        return getDataTable(list);
    }

    /**
     * 导出帖子管理列表
     */
    @RequiresPermissions("system:invitation:export")
    @Log(title = "帖子管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Invitation invitation)
    {
        List<Invitation> list = invitationService.selectInvitationList(invitation);
        ExcelUtil<Invitation> util = new ExcelUtil<Invitation>(Invitation.class);
        util.exportExcel(response, list, "帖子管理数据");
    }

    /**
     * 获取帖子管理详细信息
     */
    @RequiresPermissions("system:invitation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(invitationService.selectInvitationById(id));
    }

    /**
     * 新增帖子管理
     */
    @RequiresPermissions("system:invitation:add")
    @Log(title = "帖子管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Invitation invitation)
    {
        return toAjax(invitationService.insertInvitation(invitation));
    }

    /**
     * 修改帖子管理
     */
    @RequiresPermissions("system:invitation:edit")
    @Log(title = "帖子管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Invitation invitation)
    {
        return toAjax(invitationService.updateInvitation(invitation));
    }

    /**
     * 删除帖子管理
     */
    @RequiresPermissions("system:invitation:remove")
    @Log(title = "帖子管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(invitationService.deleteInvitationByIds(ids));
    }

    /**
     * 导入会员订单管理数据
     */
    @RequiresPermissions("system:invitation:daoru")
    @Log(title = "会员订单管理", businessType = BusinessType.IMPORT)
    @PostMapping("/daoru")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
        ExcelUtil<Invitation> util = new ExcelUtil<Invitation>(Invitation.class);
        List<Invitation> financeMemberList = util.importExcel(file.getInputStream());
        invitationService.importFinanceMember(financeMemberList);
        return success();
    }

}
